# coding=utf-8
from flask import Flask
from flask import render_template
from flask_socketio import SocketIO, emit

app = Flask(__name__)

socketio = SocketIO()
socketio.init_app(app)


@app.route('/')
def index():
    return render_template('index.html')


@socketio.on('chat message', namespace='/chat')
def give_response(data):
    value = data.get('param')
    print value
    emit('chat request', {'code': '200', 'msg': value, 'name': data.get('name')}, broadcast=True)


if __name__ == '__main__':
    socketio.run(app, debug=True, host='127.0.0.1', port=5000)
